#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/time.h>
#include <signal.h>

#include "msg_server.h"
//#include "command.h"

sig_atomic_t timeouta = 0;

void alarmer(int sig) {
    timeouta = 1;
}

void quit(int sig) {

    if (msgServerExit() == -1) {
        perror("main.msgServerExit");
        exit(1);
    }
    exit(0);
}

int main() {

    struct timeval timer;
    //int total = 1000;

    if (msgServerInit()== -1) {
        perror("main.msgServerInit");
        exit(1);
    }

    gettimeofday(&timer, NULL);
    int sec = timer.tv_sec;
//    alarm(550);
//    signal(SIGALRM, alarmer);
    signal(SIGINT, quit);

    msgServer();

    gettimeofday(&timer, NULL);
    sec = timer.tv_sec - sec;
    printf("\nelapsed time: %d sec", sec);

    if (msgServerExit()== -1) {
        perror("main.msgServerExit");
        exit(1);
    }

    return 0;

}
